package protocol.work.connection.http;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import protocol.data.util.JedisPoolUtil;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;

public class HttpWorkListener extends HttpServlet{
	private static final long serialVersionUID = 1L;

	private static Map<String,IListenerWork> iListenerWorkMap;
	
	private static JedisPool jedisPool;
	
	static{
		jedisPool = JedisPoolUtil.getJedisPool();
		iListenerWorkMap = new HashMap<String,IListenerWork>();
	}
	
	public static void addListenerWork(String listenerKey,IListenerWork iListenerWorkMap){
		HttpWorkListener.iListenerWorkMap.put(listenerKey,iListenerWorkMap);
	}
	
	protected void returnJedis(Jedis jedis) {
		if (jedis != null)
			if (jedis.isConnected())
				HttpWorkListener.jedisPool.returnResource(jedis);
			else
				HttpWorkListener.jedisPool.returnBrokenResource(jedis);
	}

	protected Jedis getJedis() {
		return (Jedis) HttpWorkListener.jedisPool.getResource();
	}
	
	public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}
	
	public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
	}
}
